﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace GameBoard
{
    [DataContract]
    public class ObjectVisualData : BaseTerrainData, IObjectFileData
    {
        [DataMember] private Point3D _centerOfTerrainFeature;

        public RotateTransform3D RotateTransform
        {
            get
            {
                var rotateTransform =
                    new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), Angle));
                return rotateTransform;
            }
        }

        public ScaleTransform3D ScaleTransform
        {
            get
            {
                var scaleTransform = new ScaleTransform3D(Scale, Scale, Scale);
                return scaleTransform;
            }
        }

        public override Material Material
        {
            get
            {
                if (!String.IsNullOrWhiteSpace(MaterialFile))
                {
                    ImageBrush imageBrush = MaterialMaker.MakeImageMaterial(MaterialFile);
                    return new DiffuseMaterial(imageBrush);
                }
                return new DiffuseMaterial(new SolidColorBrush(MaterialColor));
            }
        }

        public TranslateTransform3D TranslateTransform
        {
            get
            {
                var translateTransform = new TranslateTransform3D(_centerOfTerrainFeature.X, _centerOfTerrainFeature.Y,
                                                                  _centerOfTerrainFeature.Z + VerticalPosition);
                return translateTransform;
            }
        }

        public override Point3D CenterOfTerrainFeature
        {
            get { return _centerOfTerrainFeature; }
        }

        public override string ItemDescription
        {
            get { return Path.GetFileNameWithoutExtension(ObjectFile); }
        }

        public override double ZoomHeight
        {
            get { return 80; }
        }

        public Point3D ObjectCenter
        {
            set { _centerOfTerrainFeature = value; }
        }

        [DataMember]
        public double VerticalPosition { get; set; }

        [DataMember]
        public string ObjectFile { get; set; }

        [DataMember]
        public double Angle { get; set; }

        [DataMember]
        public double Scale { get; set; }

        [DataMember]
        public bool OverrideDefaultMaterialFile { get; set; }
    }
}